﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _11._1
{
   
    internal class Program
    {

        static void Main(string[] args)
        {
            Console.WriteLine("建立一个动物类数组 并使用它:");
            Animal[] animalArray = new Animal[2];

            Cow myCow1 = new Cow("cow1");
            animalArray[0] = myCow1;
            animalArray[1] = new Chicken("chicken1");

            foreach (Animal   item in animalArray)
            {
                Console.WriteLine($"New {item.ToString()} object added to Array collection，Name={item.Name}.");
            }

            Console.WriteLine($"Array collection contains{animalArray.Length} objects.");
            animalArray[0].Feed();
            ((Cow)animalArray[0]).Milk();
            ((Chicken)animalArray[1]).LayEgg();
            animalArray[1].Feed();
            Console.WriteLine();


            Console.WriteLine("建立一个动物类数组列表 并使用它:");
            ArrayList animalArrayList=new ArrayList();
            Cow myCow2 = new Cow("cow2");
            animalArrayList.Add(myCow2);
            animalArrayList.Add(new Chicken("chicken2"));
            foreach (Animal item in animalArrayList)
            {
                Console.WriteLine ($"New {item.ToString()} objcet added to Arraylist collection,Name={item.Name}");
            }

            Console.WriteLine($"ArrayList collection contains{animalArrayList.Count}");
            myCow2.Feed();
            ((Cow)animalArrayList[0]).Feed();
            ((Chicken)animalArrayList[1]).LayEgg();
            Console.WriteLine();

            Console.WriteLine("Additional manipulation fo Arraylist:");
            animalArrayList.RemoveAt(0);
            ((Animal)animalArrayList[0]).Feed();
            animalArrayList.AddRange(animalArray);
            ((Chicken)animalArrayList[2]).LayEgg();

            Console.WriteLine($"The Animal called {myCow1.Name} is at index{animalArrayList.IndexOf(myCow1)}.");

            myCow1.Name = "mycow3";
            Console.WriteLine($"The animal is now called{((Animal)animalArrayList[1]).Name}");
            Console.ReadLine();
        }

    }
}
